﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="JournalLedgers.aspx.cs" Culture="en-GB"
    Inherits="Main_Reports_Accounts_OutStandings_JournalLedgers" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %>
<%@ Register Src="~/User Controls/PageHeading.ascx" TagName="Heading" TagPrefix="acc" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <link href="../../../../Styles/accounts.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript">

        function validation() {
            var flag = true;
            var txtToDate = document.getElementById("txtToDate").id;
            if (document.getElementById("txtToDate").value == ' ') {
                alert('Specify ToDate');
                flag = false;
            }
            else {
                if (!isToDate(txtToDate)) {
                    flag = false;
                }
            }
            return flag;
        }

        function isToDate(txtToDateid) {
            var ctr1 = document.getElementById(txtToDateid);
            var flag = true;

            var txtToDate = ctr1.value;
            var Day = ' ';
            var Month = ' ';
            var year = ' ';
            var DateArray = new Array();
            var count = 0;

            for (var j = 0; j <= txtToDate.length; j++) {
                var chara = txtToDate.charAt(j);
                if (chara == '/') {
                    count += 1;
                }
            }
            if (count != 2) {
                alert('Invalid Date2');
                return false;
            }
            DateArray = txtToDate.split('/');
            Day = DateArray[0];
            Month = DateArray[1];
            year = DateArray[2];
            
            if (year.length != 4) {
                alert('Invalid Date4');
                return false;
            }
            if (Month.length != 2) {
                alert('Invalid Date5');
                return false;
            }
            if (Day.length > 2) {
                alert('Invalid Date6');
                return false;
            }

            var finyear = document.getElementById("hidFinyear").value;
            if (Month >= 4 && year != parseInt(finyear)) {
                alert('Date Showuld be between 01/04/' + finyear + ' 31/03/' + (parseInt(finyear) + 1));
                return false;
            }
            else if (Month < 4 && year != (parseInt(finyear) + 1)) {
                alert('Date Showuld be between 01/04/' + finyear + ' 31/03/' + (parseInt(finyear) + 1));
                return false;

            }
            if (Month == 1 || Month == 3 || Month == 5 || Month == 7 || Month == 8 || Month == 10 || Month == 12) {
                if (Day > 31) {
                    alert('Date Should not be Greater than 31');
                    Ctrl.focus();
                    flag = false;
                }


                else if (Month == 4 || Month == 6 || Month == 9 || Month == 11) {
                    if (Day > 30) {
                        alert('Date Should not be Greater than 30');
                        Ctrl.focus();
                        flag = false;
                    }
                }
                if (Month == 2) {
                    var leap = year % 4;
                    if (leap == 0)
                        if (Day > 29) {
                        alert('Date Should not be Greater than 29');
                        Ctrl.focus();
                        flag = false;
                    }
                }
                else {
                    if (Day > 28) {
                        alert('Date Should not be Greater than 29');
                        Ctrl.focus();
                        flag = false;
                    }
                }
                if (Month > 12) {
                    alert('Invalid Date7');
                    Ctrl.focus();
                    flag = false;
                }
                return flag;
            }

        }
    
    
        function checkall() {
            var table = document.getElementById("<%=grdDisplay.ClientID %>");
            var rows = table.getElementsByTagName("tr");  // Find All TR(Rows)
            for (var i = 0; i < rows.length; i++) {
                var cell = rows[i].getElementsByTagName("td"); // Find All TD(Columns)
                for (var k = 0; k < cell.length; k++) {
                    var inp = cell[k].getElementsByTagName("input"); // Find All All Input Control
                    //alert(inp.length);//
                    for (var l = 0; l < inp.length; l++) {
                        if (inp[l].type == "checkbox") {
                            inp[l].checked = document.getElementById("<%=ChkAll.ClientID %>").checked;
                        }
                    }

                }
            }
        }
        function printPartOfPage() {


            var printDiv = document.getElementById("panel1").innerHTML;
            var windowUrl = 'about:blank';
            var uniqueName = new Date();
            var windowName = 'Print' + uniqueName.getTime();
            var printWindow = window.open(windowUrl, windowName, 'left=5000,top=5000,width=0,height=0');
            printWindow.document.write(printDiv);
            printWindow.document.close();
            printWindow.focus();
            printWindow.print();
            printWindow.close();
            return false;
        }      

    </script>
</head>
<body>
    <form id="form1" runat="server">
    <asp:ScriptManager ID="scriptmanager1" runat="server" EnablePageMethods="true">
    </asp:ScriptManager>
    <asp:HiddenField ID="hidFinyear" runat="server" />
    <div class="divmain">
        <acc:Heading ID="pagehead" runat="server" HeadingText="Journal Ledgers" />
    </div>
    <div>
        <asp:Panel ID="panel" runat="server" Style="margin-left: 30%; margin-right: 20%;"
            Width="50%"> 
            <table width="60%" class="tablecontent" >
            <tr>
            <td align="center" class="headtd" >
                General Ledgers
            </td>
            </tr>
           
            </table>
            <table width="60%" class="tablecontent">
                <tr>
                    <td style="width: 100%; margin-top:40px;">
                    <div style="width:95%; height:350px; overflow:auto;" >
                        <asp:GridView ID="grdDisplay" Width="98%" Style="margin-left: 2%;" runat="server"
                            AutoGenerateColumns="false" ShowHeader="False"  CssClass="gridview">
                            <Columns>
                                <asp:TemplateField HeaderText="Select">
                                    <ItemTemplate>
                                        <asp:CheckBox ID="CheckBox1" runat="server" Width="20px" />
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:TemplateField ItemStyle-Width="400px" HeaderText="Ledger Name">
                                    <ItemTemplate  >
                                        <asp:Label ID="lblGeneralLedgers" runat="server" Text='<%#Eval("LNAME") %>'></asp:Label>
                                        <asp:HiddenField ID="hidLID" runat="server" Value='<%#Eval("LID") %>' />
                                    </ItemTemplate>
                                </asp:TemplateField>
                            </Columns>
                        </asp:GridView>
                        </div>
                    </td>
                </tr>
                <tr>
                    <td style="padding: 10px;">
                        <asp:CheckBox ID="ChkAll" runat="server" onClick="checkall();" Text="Select all Ledgers" />
                        <span style="padding:10px;">
                            <asp:Button ID="btnOk" runat="server" Text="OK" CssClass="button" OnClick="btnOk_Click" />
                            <asp:Button ID="btnClose" runat="server" Text="Close" CssClass="button" /></span>
                    </td>
                </tr>
            </table>
        </asp:Panel>
    </div>
    <div id="divPrint">
        <asp:Panel runat="server" ID="panelch" Visible="false"  style="margin-left:1%;">
            <table>
                <tr>
                    <td>
                        <asp:LinkButton ID="lnlbtn" Text="ChangeDate" runat="server"></asp:LinkButton>&nbsp;
                        <asp:HyperLink ID="hpr" Text="Print" runat="server" NavigateUrl="#" onclick=" return printPartOfPage();"></asp:HyperLink>
                        &nbsp;<asp:LinkButton ID="lnkback" runat="server" Text="Back" 
                            onclick="lnkback_Click"></asp:LinkButton>
                    </td>
                </tr>
            </table>
        </asp:Panel>
        <asp:Panel ID="panel1" runat="server" Visible="false">
            <table style="width: 100%;">
                <tr align="center">
                    <td>
                        <asp:Label ID="lblCompname" runat="server" Font-Bold="true" Font-Size="Small"></asp:Label>
                    </td>
                </tr>
                <tr align="center">
                    <td>
                        <asp:Label ID="lblHeading" runat="server"></asp:Label>
                    </td>
                </tr>
                <tr>
                    <td>
                        <div style="width:100%;">
                            <asp:GridView ID="grdDisplay1" style="margin-left:5px;"  ShowFooter="true" CssClass="gridview" Width="100%" OnRowDataBound="rowdatabound"  runat="server" AutoGenerateColumns="false">
                                <Columns>
                                    <asp:BoundField HeaderText="Date" DataField="TransactionDate" DataFormatString="{0:dd-MMM-yyyy}" ItemStyle-Width= "12%" />
                                    <asp:BoundField HeaderText="Ref No." DataField="ReferenceNumber" ItemStyle-Width="11%"/>
                                    <%-- <asp:BoundField HeaderText="Voucher No." DataField="TransactionNumber" ItemStyle-Width="12%"/>--%>
                             <asp:TemplateField HeaderText="Voucher No.">
                            <ItemTemplate>
                            <asp:HyperLink ID="hprvoucherno" NavigateUrl="#" runat="server" Text=<%#Eval("TransactionNumber") %>></asp:HyperLink>
                            </ItemTemplate>
                            </asp:TemplateField>
                                     <asp:BoundField HeaderText="Transaction" DataField="TransactionType" ItemStyle-Width="18%" />
                                    <asp:BoundField HeaderText="Party's Name" DataField="PartyName" ItemStyle-Width="7%" />
                                    <asp:BoundField HeaderText="Original A/C" DataField="OriginalAmount" ItemStyle-Width="10%" ItemStyle-HorizontalAlign="Right" />
                                    <asp:BoundField HeaderText="" DataField="OriginalAmountCrDr" HeaderStyle-Width="" />
                                    <asp:BoundField HeaderText="Received/Paid Amount" DataField="DiffAmount"  ItemStyle-HorizontalAlign="Right" ItemStyle-Width="10%" />
                                    <asp:BoundField HeaderText="Pending Amount" DataField="PendingAmount" ItemStyle-HorizontalAlign="Right" ItemStyle-Width="8%" />
                                    <asp:BoundField HeaderText="Due on" DataField="DueOn" DataFormatString="{0:dd-MMM-yyyy}" ItemStyle-Width="12%" ItemStyle-HorizontalAlign="Center" />
                                    <asp:BoundField HeaderText="Due Days" DataField="DueDays" ItemStyle-HorizontalAlign="Right" ItemStyle-Width="5%" />
                                    <asp:BoundField HeaderText="Reamrks" DataField="Remarks" ItemStyle-Width="3%"/>
                                </Columns>
                                <EmptyDataTemplate>Records Not Found !!!</EmptyDataTemplate>
                                <EmptyDataRowStyle HorizontalAlign="Center" Font-Bold="true" ForeColor="Red" Font-Size="Small" />
                            </asp:GridView>
                        </div>
                    </td>
                </tr>
            </table>
        </asp:Panel>
    </div>
    <asp:Panel ID="panel2" CssClass="modalPopup" runat="server"  Width="150px" Height="160px" Style="margin-left: 10%; display:none;">
        <table style="margin-left: 25%; margin-right: 50%; width: 100%; margin-top:5%;">
            <tr>
                <td>
                    To :&nbsp;&nbsp<asp:TextBox ID="txtToDate" Width="69%" CssClass="input" runat="server"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td>
                </td>
            </tr>
            <tr align="center">
                <td>
                    <asp:Button ID="btnShow" runat="server" CssClass="button" Text="Show" OnClientClick="return validation();" 
                        onclick="btnShow_Click" />
                    <asp:Button ID="btnCancel" runat="server" CssClass="button" Text="Cancel" />
                </td>
            </tr>
        </table>
    </asp:Panel>
    <ajaxToolkit:ModalPopupExtender ID="modalPopup" runat="server" PopupControlID="panel2"
        TargetControlID="lnlbtn" CancelControlID="btnCancel" BackgroundCssClass="modalBackground" >
    </ajaxToolkit:ModalPopupExtender>
    
    <%--<ajaxToolkit:AutoCompleteExtender
     ID="autocomplete1"
     runat="server" TargetControlID="txtLedgername"
      CompletionListCssClass="autocomplete_completionListElement" 
      CompletionListHighlightedItemCssClass="autocomplete_highlightedListItem" 
     CompletionListItemCssClass="autocomplete_listItem" DelimiterCharacters=";" 
     ServiceMethod="Getlist"
     ServicePath="~/WebServices/LedgersName.asmx"
      MinimumPrefixLength="1"
      FirstRowSelected="true" 
       CompletionInterval="0"
        EnableCaching="true"
         ShowOnlyCurrentWordInCompletionListItem="true" 
    ></ajaxToolkit:AutoCompleteExtender>--%>
   
    </form>
</body>
</html>
